<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\relation\HasMany;
use think\model\relation\HasOne;

/**
 * @mixin \think\Model
 */
class AdminParents extends Model
{
    //
    protected $autoWriteTimestamp = true;

    public function parentData(): HasOne {
        return $this->hasOne('AdminParentsData', 'parent_id', 'id')
            ->bind(['last_login_time']);
    }

    public function student(): HasMany {
        return $this->hasMany('AdminStudentParents', 'parent_id', 'id');
    }

    public function school() {
        return $this->belongsTo(AdminSchool::class, 'school_id')->where('is_delete', 0)->bind([
            'school_name' => 'name'
        ]);
    }
}
